var
    app_resources = function (app) {
        if (app)use_resources(app);
    },
    use_resources = function (app) {
        app.use(sessionGarbage);
        app.use(require('./pros_modules/auth_token/lib/sys_auth'));
        app.use(require('./pros_modules/validate_login'));//验证用户是否登录
        app.use('/', require('./routes/controller/index'));
        app.use('/users', require('./routes/controller/users'));
        app.use('/resources', require('./routes/controller/resources'));
        app.use(use_404);
        app.use(use_exception);
    },
//每次请求，session时效时间将重新计时
    sessionGarbage = function (req, res, next) {
        req.session._garbage = Date();
        req.session.touch();
        next();
    },
    use_404 = function (req, res, next) {
        var err = new Error('Not Found');
        err.status = 404;
        next(err);
    },
    use_exception = function (err, req, res, next) {
        res.status(err.status || 500);
        res.restfulfai({"exception": {"status": err.status || res.statusCode, "message": err.message}});
    };

module.exports = app_resources;